Key takeaways
- Ruby is a readable, beginner-friendly language, famous for powering Rails.
- Start with variables, strings, numbers, arrays, hashes, and methods.
- Ruby favors clean, expressive code — it often reads like English.
- Practice in irb (the interactive console) to learn fast.
- Related: Ruby object-oriented programming and from React to Rails.

Ruby basics to learn first
| Concept | Example | Use |
|---|---|---|
| Variables | name = 'Sam' | Store data |
| Arrays | [1, 2, 3] | Ordered lists |
| Hashes | {a: 1} | Key-value data |
| Methods | def greet | Reusable logic |
Here is the blog post in a clean, simple, and copy-paste-friendly format.
Lesson 1: Ruby Basics for React Developers
Welcome to the first lesson of our React to Rails series.
Before you can build APIs, you need to be comfortable with the language. The good news? If you know JavaScript, you already know 80% of the concepts. We just need to adjust the syntax.
Here is your crash course in Ruby, designed specifically for JavaScript developers.
1. Variables: No More const or let
Ruby is dynamically typed, just like JavaScript, but it is much more minimalistic. You don't need keywords to declare variables.
JavaScript:
let age = 25;
const name = "Bilal";
Ruby:
age = 25
name = "Bilal"
Key Difference:
In Ruby, we use snake_case for variable names (e.g., user_name), whereas JavaScript uses camelCase (e.g., userName).
2. Data Types
Ruby data types map very closely to the types you use in React state.
Integer:
age = 30(Same as JS Number)Float:
price = 19.99(Same as JS Number)String:
name = "Bilal"(Same as JS String)Boolean:
is_active = true(Same as JS Boolean)Nil:
data = nil(Equivalent to JSnullorundefined)
3. String Interpolation
This is one of the most common syntax switches you will need to make.
JavaScript (Backticks):
`Hello ${name}`
Ruby (Double Quotes):
"Hello #{name}"
Important Rule: You must use double quotes "" for interpolation to work in Ruby. Single quotes '' are treated as literal text.
4. Methods (Functions)
In React, you write functions constantly. In Ruby, we call them Methods.
JavaScript:
function greet(name) {
return `Hello ${name}`;
}
Ruby:
Key Differences:
def: Used to define the method.Implicit Return: You do not need to type
return. Ruby automatically returns the result of the last line of code.end: Closes the function (no curly braces{}).
5. Conditionals
If/Else logic is nearly identical, but Ruby offers a cleaner syntax that reads like English.
JavaScript:
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
Ruby:
if age >= 18
puts "Adult"
else
puts "Minor"
end
Pro Tip: Ruby allows "trailing conditionals" for one-liners. This is very popular in Rails codebases:
puts "Adult" if age >= 18
6. Output to Console
When debugging your Rails API, you will check your terminal logs, not the browser console.
JS:
console.log("Hello")Ruby:
puts "Hello"
(Note: puts stands for "put string" and adds a new line automatically.)
7. Common Mistakes for React Devs
Forgetting
end: Everydefandifblock must be closed with anend.Falsey Values: In JavaScript,
0is false. In Ruby, it0is true. Onlyfalseandnilare treated as false in Ruby.
🧠Mini Exercise
To lock in this knowledge, try writing this simple Ruby script:
Define a variable
nameandage.Write a method called
introducethat accepts these two variables as arguments.The method should print:
"My name is [NAME] and I am [AGE] years old".Call the method.
(Scroll down for the solution)
Solution:
name = "Bilal"
age = 25
def introduce(user_name, user_age)
puts "My name is #{user_name} and I am #{user_age} years old"
end
introduce(name, age)
What’s Next?
In Lesson 2, we will cover Collections (Arrays & Hashes) and the methods you will use every single day in Rails: map, each, and select.
Next Step for you: Reply with "START LESSON 2" to continue learning!
Frequently Asked Questions
What are the key tips for Lesson 1: Ruby Basics for React Developers?
Ensure you follow the recommended steps, maintain consistent updates, and adhere to proven best practices.
Frequently asked questions
Is Ruby good for beginners?
Yes. Ruby is designed to be readable and expressive, often reading almost like English, which makes it a friendly first language — especially if you plan to learn Rails.
What should I learn first in Ruby?
Start with variables, strings, numbers, arrays, hashes, and methods, then move to conditionals, loops, and objects. Practice each in the interactive irb console.
What is irb in Ruby?
irb is Ruby's interactive console where you type code and see results instantly — the fastest way to experiment and learn the basics.
Is Ruby still worth learning in 2026?
Yes, especially for web development with Rails, which remains productive and widely used. Ruby's clean style also makes it a pleasant language to learn programming with.
How long does it take to learn Ruby basics?
The fundamentals take a couple of weeks of regular practice; comfort with objects and Rails builds over a few months of projects.
Comments
Post a Comment